package cn.com.ddapp.ddm.fragment.base.landgoods;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import java.util.List;

import butterknife.BindView;
import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.adapter.ClassFicationLandSortAdpter;
import cn.com.ddapp.ddm.adapter.ClassFicationRootAdpter;
import cn.com.ddapp.ddm.adapter.ClassFicationSortAdpter;
import cn.com.ddapp.ddm.adapter.commidadapter.ThreeAdapter;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.GoodSmallSortBean;
import cn.com.ddapp.ddm.bean.HomeBean;
import cn.com.ddapp.ddm.fragment.base.BaseFragment;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.ui.GoodClassifyActivity;
import cn.com.ddapp.ddm.ui.empty.EmptyLayout;
import cn.com.ddapp.ddm.util.NetUtils;
import cn.com.ddapp.ddm.util.SPUtils;
import cn.com.ddapp.ddm.util.TLog;

/**
 * Created by Administrator on 2016/8/29 0029.//过年过节
 */
public class GuoNianFragment extends BaseFragment {
    @BindView(R.id.fenRecycler)
    GridView fenRecycler;
    @BindView(R.id.error_layout)
    EmptyLayout mEmptyLayout;
    private HomeBean homeBean;
    private int sortType;
    private List<GoodSmallSortBean.GoodSmallSort> slist;
    private ClassFicationRootAdpter rAdapter;
    private ClassFicationSortAdpter sAdapter;
    private ClassFicationLandSortAdpter slandAdapter;
    @Override
    protected String getFragmentTag() {
        return null;
    }

    @Override
    protected void initData() {

    }


    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        sortType=AppConfig.SOID;
        Log.i("aaa","--id--"+sortType);
        mEmptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
        final OkUtilCallback okCallback=new OkUtilCallback(mEmptyLayout) {
            @Override
            public void onMyResponse(String response, int id) {
                GoodSmallSortBean bean=gson.fromJson(response,GoodSmallSortBean.class);
                if((!AppConfig.RESULT_OK.equalsIgnoreCase(bean.getResult()))){
                    mEmptyLayout.setErrorType(EmptyLayout.NODATA);
                }
                else if((!AppConfig.RESULT_OK.equalsIgnoreCase(bean.getResult()))){
                    BaseApplication.getIntstance().showToast(bean.getResult(), Toast.LENGTH_SHORT,0, Gravity.CENTER);
                }else {
                    slist = bean.getSortList();
                    sAdapter=new ClassFicationSortAdpter(getActivity(),slist);
                    fenRecycler.setAdapter(sAdapter);
                    fenRecycler.setNumColumns(4);
                    fenRecycler.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                            Intent intent = new Intent(getActivity(), GoodClassifyActivity.class);
                            intent.putExtra("classiftId",slist.get(i).getLevelId());
                            String lId=slist.get(i).getLevelId();

                            startActivity(intent);
                        }
                    });

                }
            }
        };
        OKUtilAPI.post(OKUtilAPI.getGoodsort,"parentId=" + sortType,okCallback);



    }

    private void initlandData() {
//
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_land_fen;
    }

}
